Skip to content

Conversation

@itaybre
Copy link
Contributor

@itaybre itaybre commented Nov 20, 2025

Adds setAttribute and removeAttribute to SentryScope as per https://develop.sentry.dev/sdk/telemetry/scopes/#scope-methods

These attributes will be used for logs in a following PR.
Currently units are not supported since Logs don't support them (yet).

Closes #6835

@github-actions
Copy link
Contributor

github-actions bot commented Nov 20, 2025

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against ae02331

@itaybre itaybre added the ready-to-merge Use this label to trigger all PR workflows label Nov 20, 2025
@codecov
Copy link

codecov bot commented Nov 20, 2025

Codecov Report

❌ Patch coverage is 77.27273% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.062%. Comparing base (87a7e98) to head (ae02331).
⚠️ Report is 1 commits behind head on main.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
Sources/Sentry/SentryScope.m 84.210% 3 Missing ⚠️
...tions/SentryWatchdogTerminationScopeObserver.swift 0.000% 2 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##              main     #6830       +/-   ##
=============================================
+ Coverage   85.057%   85.062%   +0.004%     
=============================================
  Files          453       453               
  Lines        27633     27655       +22     
  Branches     12139     12146        +7     
=============================================
+ Hits         23504     23524       +20     
- Misses        4086      4087        +1     
- Partials        43        44        +1     
Files with missing lines Coverage Δ
Sources/Sentry/SentryCrashIntegration.m 100.000% <100.000%> (ø)
Sources/Sentry/SentryCrashScopeObserver.m 94.029% <ø> (ø)
...tions/SentryWatchdogTerminationScopeObserver.swift 75.000% <0.000%> (-5.000%) ⬇️
Sources/Sentry/SentryScope.m 96.052% <84.210%> (-0.790%) ⬇️

... and 9 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 87a7e98...ae02331. Read the comment docs.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 20, 2025

Performance metrics 🚀

  Plain With Sentry Diff
Startup time 1226.21 ms 1259.40 ms 33.18 ms
Size 24.14 KiB 1.01 MiB 1013.15 KiB

Baseline results on branch: main

Startup times

Revision Plain With Sentry Diff
d38165b 1211.41 ms 1242.49 ms 31.08 ms
409a607 1229.57 ms 1251.45 ms 21.88 ms
94a6b1a 1213.39 ms 1231.55 ms 18.17 ms
7f4bf81 1241.73 ms 1270.66 ms 28.93 ms
4d264fa 1223.48 ms 1246.91 ms 23.44 ms
c2982e7 1223.92 ms 1242.86 ms 18.94 ms
d66f082 1227.08 ms 1247.04 ms 19.96 ms
e36128b 1213.04 ms 1248.60 ms 35.56 ms
5db87fa 1218.88 ms 1251.53 ms 32.65 ms
5c2d5d6 1225.39 ms 1259.45 ms 34.06 ms

App size

Revision Plain With Sentry Diff
d38165b 23.75 KiB 855.37 KiB 831.62 KiB
409a607 23.74 KiB 874.08 KiB 850.33 KiB
94a6b1a 23.75 KiB 902.48 KiB 878.74 KiB
7f4bf81 23.75 KiB 919.70 KiB 895.95 KiB
4d264fa 23.74 KiB 874.07 KiB 850.33 KiB
c2982e7 23.75 KiB 911.62 KiB 887.87 KiB
d66f082 23.75 KiB 928.85 KiB 905.10 KiB
e36128b 23.75 KiB 963.19 KiB 939.44 KiB
5db87fa 23.75 KiB 926.65 KiB 902.90 KiB
5c2d5d6 23.75 KiB 969.28 KiB 945.54 KiB

Previous results on branch: itay/scopes_set_attributes_logs

Startup times

Revision Plain With Sentry Diff
5456d19 1221.64 ms 1256.84 ms 35.20 ms
f2aa2be 1218.04 ms 1253.26 ms 35.21 ms
263d753 1218.82 ms 1250.37 ms 31.55 ms
668b816 1210.54 ms 1247.96 ms 37.42 ms
f0909c7 1218.43 ms 1258.25 ms 39.82 ms
4f7825f 1229.96 ms 1266.36 ms 36.40 ms

App size

Revision Plain With Sentry Diff
5456d19 24.14 KiB 1.02 MiB 1016.14 KiB
f2aa2be 24.14 KiB 1.01 MiB 1015.08 KiB
263d753 24.14 KiB 1.01 MiB 1013.78 KiB
668b816 24.14 KiB 1.01 MiB 1015.68 KiB
f0909c7 24.14 KiB 1.01 MiB 1015.72 KiB
4f7825f 24.15 KiB 1.01 MiB 1015.11 KiB

Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: Attributes not cleared in clear method

The clear method was not updated to reset the attributesDictionary. As a result, scope.attributes persist on the scope object even after scope.clear() is explicitly called.

Sources/Sentry/SentryScope.m#L170-L203

return nil;
}
- (void)clear
{
// As we need to synchronize the accesses of the arrays and dictionaries and we use the
// references instead of self we remove all objects instead of creating new instances. Removing
// all objects is usually O(n). This is acceptable as we don't expect a huge amount of elements
// in the arrays or dictionaries, that would slow down the performance.
[self clearBreadcrumbs];
@synchronized(_tagDictionary) {
[_tagDictionary removeAllObjects];
}
@synchronized(_extraDictionary) {
[_extraDictionary removeAllObjects];
}
@synchronized(_contextDictionary) {
[_contextDictionary removeAllObjects];
}
@synchronized(_fingerprintArray) {
[_fingerprintArray removeAllObjects];
}
[self clearAttachments];
@synchronized(_spanLock) {
_span = nil;
}
self.userObject = nil;
self.distString = nil;
self.environmentString = nil;
self.levelEnum = kSentryLevelNone;
for (id<SentryScopeObserver> observer in self.observers) {
[observer clear];

Fix in Cursor Fix in Web


Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also update the SentryScope+Equality.m test file.

Currently units are not supported since Logs don't support them (yet).

Yes, but please double-check that we can add these without a breaking change. I think we should be good because we will simply add method overloads, but it is still worth checking if that works.

We should merge this PR including #6834 to main cause otherwise the attributes are useless. Thanks for splitting this up into two PRs.

@itaybre
Copy link
Contributor Author

itaybre commented Nov 25, 2025

Please also update the SentryScope+Equality.m test file.

Currently units are not supported since Logs don't support them (yet).

Yes, but please double-check that we can add these without a breaking change. I think we should be good because we will simply add method overloads, but it is still worth checking if that works.

We should merge this PR including #6834 to main cause otherwise the attributes are useless. Thanks for splitting this up into two PRs.

We can just add a new method with the unit parameter, I initially had it like that until I realized we cannot use the unit at this moment.

I am waiting to merge this one and then the other PR.

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I found one potential bug. Almost LGTM

Copy link
Member

@philipphofmann philipphofmann left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but maybe wait with merging after we release 9.0.0, so the release doesn't blow up even further.

@itaybre
Copy link
Contributor Author

itaybre commented Dec 1, 2025

LGTM, but maybe wait with merging after we release 9.0.0, so the release doesn't blow up even further.

That was my plan 👍

@itaybre itaybre force-pushed the itay/scopes_set_attributes_logs branch from 8a02d8b to ae02331 Compare December 1, 2025 14:54
@itaybre itaybre merged commit 7f6a9a5 into main Dec 1, 2025
207 of 210 checks passed
@itaybre itaybre deleted the itay/scopes_set_attributes_logs branch December 1, 2025 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-to-merge Use this label to trigger all PR workflows Waiting for: Review ⏳

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat: Add attributes data to SentryScope

3 participants